#include <iostream>
using namespace std;

int Getfirstkindex(int data[], int start, int end,int k)
{
	if (start>end)
	{
		return -1;
	}
	int middle=(start+end)/2;
	int middledata=data[middle];
	if (middledata==k)
	{
		if (middle>0&&data[middle-1]!=k||middle==0)
		{
			return middle;
		}
		else
			end=middle-1;
	}
	else if (middledata<k)
	{
		start=middle+1;
	}
	else
	{
		end=middle-1;
	}

	return Getfirstkindex(data, start, end, k);

}

int Getlastkindex(int data[], int start, int end, int k)
{
	if (start>end)
	{
		return -1;
	}
	int middle=(start+end)/2;
	int middledata=data[middle];
	if (middledata==k)
	{
		if ((middle<end&&data[middle+1]!=k)||middle==end)
		{
			return middle;
		}
		else
			start=middle+1;
	}
	else if (middledata<k)
	{
		start=middle+1;
	}
	else
	{
		end=middle-1;
	}
	return Getlastkindex(data, start, end, k);
}

int main()
{
	int a[]={1,3,3,3,3,3,4,5};
	int k1=Getfirstkindex(a,0,7,3);
	int k2=Getlastkindex(a,0,7,3);
	cout<<k2-k1+1<<endl;
	return 0;

}